home *** CD-ROM | disk | FTP | other *** search
Text File | 1994-10-01 | 8.8 KB | 478 lines | [TEXT/MPCC] |
-
- /********************************************
- **** ACL-World
- ****
- **** main.cp
- ****
- **** Created: 21 August 1994
- **** Modified: 29 August 1994
- **** Version: 0
- **** Compatible: C++, Mac System 7
- ****
- **** Description: Main part of the demo
- ****
- *******************/
-
- #include "ACL-World.h"
-
-
- //****************************************
-
-
- static const short PICT_PERS = 130;
- static const short PICT_SHOCKPERS = 139;
- static const short PICT_FLYPERS = 144;
-
- static const short PICT_BACKGROUND = 138;
-
- static const short PICT_A = 135;
- static const short PICT_C = 136;
- static const short PICT_L = 137;
-
-
- AnimFrameDef animpers[] = {{PICT_PERS+2,NULL,2,0,0,afcmd_frame},
- {PICT_PERS+3,NULL,2,0,0,afcmd_frame},
- {PICT_PERS+4,NULL,2,0,0,afcmd_frame},
- {PICT_PERS+3,NULL,2,0,0,afcmd_frame},
- {PICT_PERS+2,NULL,2,0,0,afcmd_frame},
- {PICT_PERS+0,NULL,2,0,0,afcmd_frame},
- {PICT_PERS+1,NULL,2,0,0,afcmd_endsequence},
- {PICT_SHOCKPERS+0,NULL,1,0,0,afcmd_frame},
- {PICT_SHOCKPERS+1,NULL,1,0,0,afcmd_frame},
- {PICT_SHOCKPERS+2,NULL,1,0,0,afcmd_endsequence},
- {PICT_FLYPERS+0,NULL,3,0,0,afcmd_frame},
- {PICT_FLYPERS+1,NULL,3,0,0,afcmd_frame},
- {PICT_FLYPERS+2,NULL,3,0,0,afcmd_endanim}};
-
-
-
- AnimControl perscontrols[2];
- AnimControl a_controls[4];
- AnimControl l_controls[4];
-
-
-
- //****************************************
-
- void ACLWorld::inittoolbox()
- {
- InitGraf((Ptr) &qd.thePort);
- InitFonts();
- InitWindows();
- InitMenus();
- FlushEvents(everyEvent,0);
- TEInit();
- InitDialogs(0L);
- InitCursor();
-
- GetDateTime((unsigned long*)&qd.randSeed); // Initializes the random number generator
- }
-
- //****************************************
-
-
- ACLWorld::ACLWorld()
- {
- long l;
-
- inittoolbox();
- initmenubar();
- introwarning();
-
- }
-
- //****************************************
-
- ACLWorld::~ACLWorld()
- {
- freemenubar();
- }
-
- //****************************************
-
-
- void ACLWorld::run(void)
- {
- Boolean done = FALSE;
- EventRecord theEvent;
- WindowPtr whichWindow;
- DialogPtr whichDlog;
- short itemHit;
- short part;
-
- initmenu();
-
-
- while(!done)
- {
- animbase->update();
-
- if (WaitNextEvent(everyEvent,&theEvent,0,NULL))
- {
- if(DialogSelect(&theEvent,&whichDlog,&itemHit))
- {
- switch(itemHit)
- {
- case 2: // intro demo
- closemenu();
- if (do_intro()) return;
- initmenu();
- break;
-
- case 3: // Controls demo
- closemenu();
- if (do_controls()) return;
- initmenu();
- break;
-
- case 4: // Composed anim demo
- closemenu();
- if (do_companim()) return;
- initmenu();
- break;
-
- case 5: // Sorting demo
- closemenu();
- if (do_sorting()) return;
- initmenu();
- break;
-
- case 6: // Collisions demo
- closemenu();
- if (do_collisions()) return;
- initmenu();
- break;
-
- case 7: // Animmask demo
- closemenu();
- if (do_animmask()) return;
- initmenu();
- break;
-
- case 8: // Scrolling demo
- closemenu();
- if (do_scrolling()) return;
- initmenu();
- break;
-
-
- }
- }
-
- switch(theEvent.what)
- {
- case updateEvt:
- whichWindow = (WindowPtr)theEvent.message;
- if (whichWindow==dialog)
- {
- BeginUpdate(whichWindow);
- animbase->updatewindow();
- EndUpdate(whichWindow);
- }
- break;
-
- case keyDown:
- done = docmdkey(&theEvent);
- break;
-
-
- case mouseDown:
- part = FindWindow(theEvent.where,&whichWindow);
- if (whichWindow==dialog)
- {
- switch(part)
- {
- case inGoAway:
- done = TrackGoAway(whichWindow,theEvent.where);
- break;
-
- case inDrag:
- DragWindow(whichWindow,theEvent.where,&qd.screenBits.bounds);
- break;
- }
- }
- else
- {
- switch(part)
- {
- case inMenuBar:
- done = domenubar(MenuSelect(theEvent.where));
- break;
- }
- }
-
- break;
-
- }
- }
- }
-
-
- closemenu();
- }
-
-
- //****************************************
-
- Boolean ACLWorld::docmdkey(EventRecord *event)
- {
- char c;
-
- c = event->message & charCodeMask;
- if (event->modifiers & cmdKey)
- {
- return domenubar( MenuKey(c) );
- }
-
- return FALSE;
- }
-
-
- //****************************************
-
- Boolean ACLWorld::domenubar(long menuResult)
- {
- short menuID,itemNumber;
- Boolean res = FALSE;
- Str255 str;
-
- menuID = HiWord(menuResult);
- itemNumber = LoWord(menuResult);
-
- if (menuID==2 && itemNumber==1) res = TRUE;
-
- if (menuID==1)
- {
- if (itemNumber==1) about();
- else
- {
- GetItem(menus[0],itemNumber,str);
- OpenDeskAcc(str);
- }
- }
-
- HiliteMenu(0);
-
- return res;
- }
-
-
- //****************************************
-
- static AnimGfx *background;
- static short backwidth,backheight;
- static Anim *anim_pers,*anim_a, *anim_c, *anim_l;
-
-
- Boolean testanimpers(AnimCObject *a, AnimControl *c) // Used to test if the anim is out of screen.
- {
- if (a->getx()>=backwidth) return TRUE;
-
-
- if (anim_pers->checkcollision(anim_a) ||
- anim_pers->checkcollision(anim_c) ||
- anim_pers->checkcollision(anim_l))
- {
- if (anim_pers->getcurrentsequence()!=1)
- {
- anim_pers->setsequence(1);
- anim_pers->move(0,-20);
- }
- }
- else if (anim_pers->getcurrentsequence()!=0)
- {
- anim_pers->setsequence(0);
- anim_pers->move(0,20);
- }
-
- return FALSE;
- }
-
-
- void ACLWorld::initmenu(void)
- {
- Anim *anim;
- short w,h,cw,cx,cy,ch;
-
- pleasewait(TRUE);
-
- animbase = new AnimBase();
-
-
- background = animbase->newgfx(PICT_BACKGROUND);
- backwidth = background->getwidth();
- backheight = background->getheight();
-
- animbase->installbackground(background);
- animbase->buildbufferback();
- animbase->setbasex(23);
- animbase->setbasey(8);
-
- animbase->setsortflags(ASORT_PRIORITY);
-
- anim_pers = anim = animbase->createanim(animpers);
-
- anim->findmaxsize(&w,NULL);
- anim->place(-w,18); // Place animation
- anim->setpriority(-10);
- anim->setcollisionkey_me(2);
- anim->setcollisionkey_hit(1);
-
-
- perscontrols[0].cmd = acmd_move;
- perscontrols[0].x = 2;
- perscontrols[0].y = 0;
- perscontrols[0].next = &perscontrols[1];
-
- perscontrols[1].cmd = acmd_place;
- perscontrols[1].x = -w;
- perscontrols[1].y = 18;
- perscontrols[1].testproc = &testanimpers;
- perscontrols[1].next = &perscontrols[0];
-
- anim->runcontrol(perscontrols);
-
-
- anim_c = anim = animbase->createanim(PICT_C);
- anim->findmaxsize(&cw,&ch);
- cx = (backwidth/2)-(cw/2);
- cy = (backheight/2)-(ch/2);
- anim->place(cx,cy);
- anim->setpriority(0);
- anim->setcollisionkey_me(1);
- anim->setcollisionkey_hit(2);
-
-
- anim_a = anim = animbase->createanim(PICT_A);
- anim->findmaxsize(&w,NULL);
- anim->place(cx-(w+5),cy);
- anim->setpriority(0);
- anim->setcollisionkey_me(1);
- anim->setcollisionkey_hit(2);
-
-
- a_controls[0].cmd = acmd_setpriority;
- a_controls[0].data = -5;
- a_controls[0].next = &a_controls[1];
-
- a_controls[1].cmd = acmd_goto;
- a_controls[1].x = cx+(cw+5);
- a_controls[1].y = cy;
- a_controls[1].speed = 4;
- a_controls[1].acceleration = 0;
- a_controls[1].next = &a_controls[2];
-
- a_controls[2].cmd = acmd_setpriority;
- a_controls[2].data = 5;
- a_controls[2].next = &a_controls[3];
-
- a_controls[3].cmd = acmd_goto;
- a_controls[3].x = cx-(w+5);
- a_controls[3].y = cy;
- a_controls[3].speed = 4;
- a_controls[3].acceleration = 0;
- a_controls[3].next = &a_controls[0];
-
- anim->runcontrol(a_controls);
-
-
- anim_l = anim = animbase->createanim(PICT_L);
- anim->findmaxsize(&w,NULL);
- anim->place(cx+(cw+5),cy);
- anim->setpriority(0);
- anim->setcollisionkey_me(1);
- anim->setcollisionkey_hit(2);
-
-
- l_controls[0].cmd = acmd_setpriority;
- l_controls[0].data = 5;
- l_controls[0].next = &l_controls[1];
-
- l_controls[1].cmd = acmd_goto;
- l_controls[1].x = cx-(w+5);
- l_controls[1].y = cy;
- l_controls[1].speed = 4;
- l_controls[1].acceleration = 0;
- l_controls[1].next = &l_controls[2];
-
- l_controls[2].cmd = acmd_setpriority;
- l_controls[2].data = -5;
- l_controls[2].next = &l_controls[3];
-
- l_controls[3].cmd = acmd_goto;
- l_controls[3].x = cx+(cw+5);
- l_controls[3].y = cy;
- l_controls[3].speed = 4;
- l_controls[3].acceleration = 0;
- l_controls[3].next = &l_controls[0];
-
- anim->runcontrol(l_controls);
-
-
-
- dialog = GetNewDialog(dlg_FIRSTMENU,NULL,(WindowPtr)-1);
-
- pleasewait(FALSE);
-
-
- ShowWindow(dialog);
- SetPort(dialog);
- }
-
- //****************************************
-
- void ACLWorld::closemenu(void)
- {
- delete animbase;
- DisposDialog(dialog);
- }
-
- //****************************************
-
- void ACLWorld::initmenubar()
- {
- short i;
-
- for(i=0;i<3;i++)
- {
- menus[i] = GetMenu(i+1);
- InsertMenu(menus[i],0);
- }
-
- AddResMenu(menus[0],'DRVR');
-
- DrawMenuBar();
- }
-
- void ACLWorld::freemenubar()
- {
- short i;
-
- for(i=0;i<3;i++)
- {
- DeleteMenu(i+1);
- ReleaseResource((Handle)menus[i]);
- }
- }
-
-
- //****************************************
-
- #define sysevtmask (*((short*)0x0144))
-
- void main(void)
- {
- ACLWorld *app;
- short oldmask;
-
- oldmask = sysevtmask;
- sysevtmask |= keyUpMask; // I want keyUp events
-
- app = new ACLWorld();
- app->run();
- delete app;
-
- sysevtmask = oldmask;
- }
-
-